package com.glsc.ngateway.platform.controller;

import com.glsc.ngateway.common.api.platform.resp.PlatformResponse;
import com.glsc.ngateway.common.base.utils.redis.IbltRedis;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @author xuchang
 */
@RestController
@RequestMapping("/redis")
@Api(value = "redis", tags = {"redis"})
public class RedisController {

    @Resource
    private IbltRedis ibltRedis;

    @RequestMapping(method = RequestMethod.GET, value = "get")
    @ApiOperation(value = "查看key", notes = "查看key")
    public PlatformResponse<String> get(@RequestParam("key") String key) {
        return PlatformResponse.successData(ibltRedis.getValueByKey(key));
    }

    @RequestMapping(method = RequestMethod.GET, value = "del")
    @ApiOperation(value = "删除key", notes = "删除key")
    public PlatformResponse<Boolean> del(@RequestParam("key") String key) {
        return PlatformResponse.successData(ibltRedis.deleteByKey(key));
    }

    @RequestMapping(method = RequestMethod.GET, value = "set")
    @ApiOperation(value = "设置key", notes = "设置key")
    public PlatformResponse<?> set(@RequestParam("key") String key, @RequestParam("val") String value) {
        ibltRedis.set(key, value);
        return PlatformResponse.success();
    }
}